﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThaireInvestmentWeb.Util;
using ThaireInvestmentWeb.WcfSerivce;

namespace ThaireInvestmentWeb.Models
{
    public class EditUnitTrustProportionModel
    {
        public UnitTrustProportionScreenData ScreenData { get; set; }
        public UnitTrustHeaderDTO HeaderDTO { get; set; }
        public UnitTrustProportion Proportion { get; set; }
        public EditUnitTrustProportionModel()
        {
            Init();
        }
        void Init()
        {
            if (HeaderDTO == null)
                HeaderDTO = new UnitTrustHeaderDTO();
            if (HeaderDTO.Header == null)
                HeaderDTO.Header = new UnitTrustHeader();
            if (null == Proportion)
                Proportion = new UnitTrustProportion();
        }

        public static EditUnitTrustProportionModel BuildModel(UnitTrustProportionScreenData data)
        {
            if (data.HeaderDTO == null || data.HeaderDTO.Header == null)
                throw new Exception("Please save a Header before.");

            var model = new EditUnitTrustProportionModel { HeaderDTO = data.HeaderDTO, ScreenData = data};
            model.HeaderID = model.HeaderDTO.Header.ID;
            if (model.Proportion != null)
                model.ProportionID = model.Proportion.ID;
            return model;
        }

        #region adapter data
        public int HeaderID
        {
            get
            {
                return Proportion.UnitTrustHeaderID.GetValueOrDefault();
            }
            set
            {
                Proportion.UnitTrustHeaderID = value;
            }
        }
        public int? ProportionID
        {
            get
            {
                return Proportion.ID;
            }
            set
            {
                Proportion.ID = value.GetValueOrDefault();
            }
        }

        //AsOfDate
        [Display(Name = "As of Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime? UnitTrustDate
        {
            get
            {
                return Proportion.UnitTrustDate;
            }
            set
            {
                Proportion.UnitTrustDate = value;
            }
        }

        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem1
        {
            get
            {
                return Proportion.UnitTrustItem1;
            }
            set
            {
                Proportion.UnitTrustItem1 = value;
            }
        }

        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem2
        {
            get
            {
                return Proportion.UnitTrustItem2;
            }
            set
            {
                Proportion.UnitTrustItem2 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem3
        {
            get
            {
                return Proportion.UnitTrustItem3;
            }
            set
            {
                Proportion.UnitTrustItem3 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem4
        {
            get
            {
                return Proportion.UnitTrustItem4;
            }
            set
            {
                Proportion.UnitTrustItem4 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem5
        {
            get
            {
                return Proportion.UnitTrustItem5;
            }
            set
            {
                Proportion.UnitTrustItem5 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem6
        {
            get
            {
                return Proportion.UnitTrustItem6;
            }
            set
            {
                Proportion.UnitTrustItem6 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem7
        {
            get
            {
                return Proportion.UnitTrustItem7;
            }
            set
            {
                Proportion.UnitTrustItem7 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem8
        {
            get
            {
                return Proportion.UnitTrustItem8;
            }
            set
            {
                Proportion.UnitTrustItem8 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem9
        {
            get
            {
                return Proportion.UnitTrustItem9;
            }
            set
            {
                Proportion.UnitTrustItem9 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem10
        {
            get
            {
                return Proportion.UnitTrustItem10;
            }
            set
            {
                Proportion.UnitTrustItem10 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem111
        {
            get
            {
                return Proportion.UnitTrustItem111;
            }
            set
            {
                Proportion.UnitTrustItem111 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem112
        {
            get
            {
                return Proportion.UnitTrustItem112;
            }
            set
            {
                Proportion.UnitTrustItem112 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem113
        {
            get
            {
                return Proportion.UnitTrustItem113;
            }
            set
            {
                Proportion.UnitTrustItem113 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem114
        {
            get
            {
                return Proportion.UnitTrustItem114;
            }
            set
            {
                Proportion.UnitTrustItem114 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem121
        {
            get
            {
                return Proportion.UnitTrustItem121;
            }
            set
            {
                Proportion.UnitTrustItem121 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem122
        {
            get
            {
                return Proportion.UnitTrustItem122;
            }
            set
            {
                Proportion.UnitTrustItem122 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem123
        {
            get
            {
                return Proportion.UnitTrustItem123;
            }
            set
            {
                Proportion.UnitTrustItem123 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem124
        {
            get
            {
                return Proportion.UnitTrustItem124;
            }
            set
            {
                Proportion.UnitTrustItem124 = value;
            }
        }
        [Display(Name = "สัดส่วนการลงทุน")]
        public decimal? UnitTrustItem125
        {
            get
            {
                return Proportion.UnitTrustItem125;
            }
            set
            {
                Proportion.UnitTrustItem125 = value;
            }
        }


        #endregion

        public bool IsThaireLifeCompany
        {
            get
            {
                if (HeaderDTO != null && HeaderDTO.Header.UnitTrustCompanyName != null && HeaderDTO.Header.UnitTrustCompanyName.ToUpper().Contains(ConfigurationManager.AppSettings["ThaireLifeCompany"]))
                {
                    return true;
                }
                return false;
            }
        }



        public String SubmitBtn { get; set; }
        public String CancelBtn { get; set; }
        public bool UpdateMode { get; set; }
    }
}